package com.lc202309;

/**
 * Description:
 *
 * @Create 2023/9/5 22:43
 * @Version 1.0
 */
public class Solution2511 {
    public int captureForts1(int[] forts) {
        int start = 0;
        int tmp = 0;
        int size = 0;
        for (int i = 0; i < forts.length; i++) {
            // 得到初始值
            if (tmp == 0) {
                tmp = forts[i];
                start = i;
                continue;
            }
            if (forts[i] == 0) {
                continue;
            }
            if (tmp + forts[i] == 0) {
                tmp = forts[i];
                size = Math.max(size, i - start - 1);
            }
            start = i;

        }
        return size;
    }

    public int captureForts(int[] forts) {
        int start = 0;
        int size = 0;
        for (int i = 0; i < forts.length; i++) {
            // 得到初始值
            if (forts[start] == 0) {
                start = i;
                continue;
            }
            if (forts[i] == 0) {
                continue;
            }
            if (forts[start] + forts[i] == 0) {
                size = Math.max(size, i - start - 1);
            }
            start = i;

        }
        return size;
    }
}
